package com.example.springbootServiceNetwork.demos.web.Controller;

import com.example.springbootServiceNetwork.demos.web.Dto.MessageDto;
import com.example.springbootServiceNetwork.demos.web.WebSocket.WebSocketServer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * websocket接口
 */

@Controller
@RequestMapping(value = "/message")
public class WebSocketController {
    @Resource
    private WebSocketServer webSocketServer;

    /**
     * webSoket 群发消息
     */
    @PostMapping("/sendAll")
    public Object sendTestMessage(@RequestBody MessageDto messageDTO) {
        try {
            webSocketServer.sendAllMessage(messageDTO.getContent());
        } catch (Exception e) {
            e.fillInStackTrace();
            return e;
        }
        return null;
    }

}
